#include <bits/stdc++.h>
using namespace std;
struct ListNode {
	int val;
	ListNode *next;
	ListNode(int x) : val(x), next(NULL) {}
};
class Test{
public:
	ListNode *detectCycle(ListNode *head) {
		ListNode* fast = head;
		ListNode* slow = head;
		int flag = false;
		while(fast != NULL && fast->next != NULL){
			fast = fast->next->next;
			slow = slow->next;
			if(fast == slow){
				flag = true;
				break;
			}
		}
		if(flag){
			ListNode* curA = head;
			ListNode* curB = slow;
			while(curA != curB){
				curA = curA->next;
				curB = curB->next;
			}
			return curA;
		}
		return NULL;
	}
};


int main(){
	
	return 0;
}
